import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import routes from './routerMap'
 // import { ElLoading } from 'element-plus'
 // let loading

// console.log(routes)

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
	// loading= ElLoading.service({
	//      lock: true,
	//      text: 'Loading',
	//      background: 'rgba(0, 0, 0, 0.7)',
	// })
	let token = localStorage.getItem('token')
	if (token || to.path === '/login') {
		next()
	} else {
		next('/login')
	}
})

router.afterEach(()=>{
	// loading.close()
})

export default router
